﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace EBA.Xaml
{
    /// <summary>
    /// http://blog.csainty.com/2009/12/wpf-multibinding-and.html
    /// </summary>
    public class MultiBooleanToVisibilityConverter : IMultiValueConverter
    {
        public MultiBooleanToVisibilityConverter()
            : this(Visibility.Visible, Visibility.Collapsed)
        {
        }

        public MultiBooleanToVisibilityConverter(Visibility trueValue, Visibility falseValue)
        {
            this.TrueValue = trueValue;
            this.FalseValue = falseValue;
        }

        Visibility TrueValue { get; set; }
        Visibility FalseValue { get; set; }

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                if (values.Any(i => (bool)i == false))
                {
                    return this.FalseValue;
                }
                else
                {
                    return this.TrueValue;
                }
            }
            catch
            {
                return this.FalseValue;
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
